home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8275 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: hkusuc.hku.hk!hkusua!h8716718
  3. From: h8716718@hkusua.hku.hk (Starry Hung)
  4. Subject: Problem Negating an Unsigned Char
  5. X-Nntp-Posting-Host: hkusua.hku.hk
  6. Message-ID: <Dnnros.Lq.0.-s@hkusuc.hku.hk>
  7. Sender: usenet@hkusuc.hku.hk
  8. Organization: The University of Hong Kong
  9. X-Newsreader: TIN [version 1.1 PL6]
  10. Date: Sat, 2 Mar 1996 21:00:27 GMT
  11.  
  12. Hi,
  13.  
  14. I have tested the following simple code on at least two C compilers,
  15. including the Borland C 3.1, and find that it consistently generates
  16. the same results.  The experiment convinces me that I should do the
  17. coding in a little bit redundant way (add a casting), however, I can't
  18. convince myself why the language performs like this, should anybody
  19. kindly tell me the story?
  20.  
  21. The code is like that:
  22.  
  23. unsigned char a=0x11;
  24. unsigned char b=0xEE;
  25. int c=0;
  26.  
  27. void main( void ) {
  28.     if( a == ~b ) {
  29.       c=1;
  30.     }
  31. }
  32.  
  33. The c remains unchange, while it changes to 1 if I cast the ~b to unsigned
  34. char as if( a == (unsigned char) ~b )
  35.  
  36. I browse through the FAQ but can't find the related discussion,
  37. apologise if I overlook on the list.
  38.  
  39.  
  40. Starry Hung.
  41.